<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>发布拍品</title>
<link rel="stylesheet" href="<?php echo TEMPLATE_SITE_URL;?>/css/style.css" type="text/css">
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/zepto.js" charset="utf-8"></script>

</head>
<body><div style="margin-top:20px;"></div>
<div id="section_login">

<section>
<header><input type="hidden" id="zc_id" value="<?php echo $output["zc_id"];?>" />
	<div class="header-box">
		<a href="javascript:;" id="caogao" class="new-btn new-btn-orange new-btn-back">存为草稿</a>
		<a href="javascript:;" id="J_submit" class="nextBn">下一步</a>
	</div>
</header>
	<div id="dp_banner"></div>
	<form id="J_login_form" method="post">
		<div class="login-frame verification-login">
			<ul>
				<li>
					<p class="input-box">
						<textarea name="auction_description" rows="5" cols="40" id="auction_description" placeholder="描述信息。。。" value=''><?php echo $output['auction']['auction_description']?></textarea>													
					</p>
				</li>
				<li>
					<?php if(!empty($output['auction_img'])){?>
					<?php foreach($output['auction_img'] as $val){?>
					<div class="productImg" i="<?php echo $val['id'];?>">
						<img class="showimg" src="<?php echo BASE_SITE_URL;?>/data/upload/shop/auction/<?php echo $output['auction']['auction_add_date'];?>/<?php echo $val['auction_img'];?>">
						<div class="deleteImg" j="<?php echo $val['id'];?>"><img src="<?php echo TEMPLATE_SITE_URL?>/images/deleteImg.png" width="21" height="21"></div>
					</div>
					<?php }?>
					<?php }?>
			      	<div class="addImg publish" style="<?php if($output['auction_count']>8){ echo 'display:none;';}?>"><img src="<?php echo TEMPLATE_SITE_URL;?>/images/addImg.jpg"></div>
                   	<div style="clear:both;"></div>

				</li>
			</ul>
			<p class="n-tips" style="display:none;"><a href="<?php echo $output['plat_guize']['value'];?>">下一步即表示同意《竞拍服务协议》</a></p>
			<div class="login-btn">
				<input type="hidden" name="auction_count" value="<?php echo $output['auction_count'];?>">
				<input type="hidden" name="auction_id" value="<?php echo $output['auction']['id']?>" id="auction_id" >
			</div>
			
		</div>
		<input type="hidden" name="video_url" id="video_url" value="<?php echo $output['auction']['auction_video']?>"> 
	</form>
<form  id="xy_sc" action="/ajaxupload/upload.php?auction_id=<?php echo $_GET['auction_id'];?>&video_url=<?php echo $output['auction']['auction_video'];?>" method="post" enctype="multipart/form-data">
<h2>上传展示视频</h2>
<div id="xy_shipin"></div>
<div id="progress" style="width:100%;text-align:center;"></div>
<input type="file" name="pic" accept="video/mp4" id="xy_sc_select_file">
<input type="button" value="上传" id="xy_sc_button" onClick="ajaxup();"/>
</form><script type="text/javascript">function ajaxup(){ var ifname='up'+Math.random(); var video_url=$("#video_url").val();var xy_file_size=document.getElementById('xy_sc_select_file').files[0].size;if(xy_file_size/1024/1024>20){	alert("上传超限制");	}else{ if(video_url!=""){	 $("#xy_shipin").children('video').remove(); } $('<iframe name="'+ifname+'" width="0" height="0" frameBorder="0"></iframe>').appendTo($('body')); $('#xy_sc').attr('target',ifname); $('#xy_sc_select_file').hide(); $('#xy_sc_button').hide(); $('#progress').html('<div style="text-align:center;">正在上传请稍后。。。。。。</div><img src="/ajaxupload/timg.gif" style="width:100%">'); $('#xy_sc').submit();}} </script>

</section>

<style>
.loaddingBg {width:100%;height:100%;position:fixed;top:0px;left:0px;}
.loading1{color:#fff;width:200px;height:85px;background:rgba(0, 0, 0, 0.7);margin-left:auto;margin-right:auto;border-radius:6px;margin-left:auto;margin-right:auto;margin-top:200px;}
.loading-top {height:40px;padding-top:10px;clear:both;}
.loading-top img {margin-top:0px;margin-left:30px;float:left;}
.loading-top span{margin-top:12px;font-size:14px;float:left;}
.loading-bottom {height:30px;clear:both;}
.loading-bottom p {margin-top:3px;text-align:center;font-size:14px;}
</style>

<div class="loaddingBg" style="display:none;">
    <div class="loading1">
        <div class="loading-top"><img src="<?php echo TEMPLATE_SITE_URL;?>/images/loadingData.gif" width="45" height="45" /><span style="padding:">正上传中...</span></div>
        <div class="loading-bottom"><p><span class="readynumpic"></span>&nbsp;/&nbsp;<span class="totalpic"></span></p></div>
    </div>
</div>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
    appId: '<?php echo $output['signPackage']["appId"];?>',
    timestamp: <?php echo $output['signPackage']["timestamp"];?>,
    nonceStr: '<?php echo $output['signPackage']["nonceStr"];?>',
    signature: '<?php echo $output['signPackage']["signature"];?>',
   jsApiList: [
               'checkJsApi',
               'onMenuShareTimeline',
               'onMenuShareAppMessage',
               'onMenuShareQQ',
               'onMenuShareWeibo',
               'hideMenuItems',
               'showMenuItems',
               'hideAllNonBaseMenuItem',
               'showAllNonBaseMenuItem',
               'translateVoice',
               'startRecord',
               'stopRecord',
               'onRecordEnd',
               'playVoice',
               'pauseVoice',
               'stopVoice',
               'uploadVoice',
               'downloadVoice',
               'chooseImage',
               'previewImage',
               'uploadImage',
               'downloadImage',
               'getNetworkType',
               'openLocation',
               'getLocation',
               'hideOptionMenu',
               'showOptionMenu',
               'closeWindow',
               'scanQRCode',
               'chooseWXPay',
               'openProductSpecificView',
               'addCard',
               'chooseCard',
               'openCard'
      ]
  });
$(function(){

	var images = {
			  localId: [],
			  serverId: []
	};
	$('.publish').click(function(){
		  wx.chooseImage({
			    success: function (res) {
			      	images.localId = res.localIds;
			      	if (images.localId.length == 0) {
			          alert('请先使用 chooseImage 接口选择图片');
			          return;
			        }
			        
			        var i = 0, length = images.localId.length;
			        var count = parseInt($('input[name=auction_count]').val());
					
					if(eval(length+count)>9){
				          alert('最多可以上传9张拍品图片');
				          return;
					}
					
	            	$('.readynumpic').html(0);
	            	$('.totalpic').html(images.localId.length);
			        $('.loaddingBg').show();  
			        
			        images.serverId = [];
			        function upload() {
			          wx.uploadImage({
			            localId: images.localId[i],
			            isShowProgressTips: 0,
			            success: function (res) {
			              i++;
			              images.serverId.push(res.serverId);
			              $('.readynumpic').html(i);
			              $('.totalpic').html(length);
			              if (i < length) {
			                upload();
			              }else{
							var str = images.serverId;
							var pdata = str.join(',');
							var seller_id = '<?php echo $output['auction']['seller_id'];?>';
							var auction_id = '<?php echo intval($_GET['auction_id']);?>'
							$.ajax({
								type:'post',
								url:'index.php?act=upload&op=addauction',
								data:{pdata:pdata,seller_id:seller_id,auction_id:auction_id},
								dataType:'json',
								success:function(data){
									if(data.state){
										location.reload();
									}								
									return false;										
								}
							});
				          }
			            },
			            fail: function (res) {
			              alert(JSON.stringify(res));
			            }
			          });
			        }

			        upload();				    	        
			    }
		  });
	});
	
	$('.showimg').click(function(){
		var current = $(this).attr('src');
		var images = {};
		images.current = current;
		images.urls = [];
		$('.showimg').each(function(){
			images.urls.push($(this).attr('src'));
		});
		
		wx.previewImage(images);
	});

	
	
	$('.deleteImg').click(function(){
		var img_id = $(this).attr('j');
		var auction_id = '<?php echo $_GET['auction_id']?>';
		var auction_count = parseInt($('input[name=auction_count]').val());
		$.ajax({
			type:'post',
			url:'index.php?act=publish&op=delimg',
			data:{img_id:img_id,auction_id:auction_id},
			dataType:'json',
			success:function(data){
				if(data.state){
					$('input[name=auction_count]').val(eval(auction_count-1));
					$("div[i='"+img_id+"']").remove();
					$('.addImg').show();
				}
				return false;
			}
		});
	});
	
	$('#J_submit,#caogao').click(function(){
		var type = $(this).attr('id');

		var auction_id = $('#auction_id').val();
		var auction_description = $('#auction_description').val();
		var auction_video_url=$('#video_url').val();
		if(auction_description == ''){
			alert('描述信息不能为空');
			return false;
		}		
		
		$.ajax({
			type:'post',
			url:'index.php?act=publish&op=index',
			dataType:'json',
			data:{auction_id:auction_id,auction_description:auction_description,auction_video_url:auction_video_url},
			success:function(data){
				if(data.state == 1){
					$('#account_err').html(data.error);
					return false;
				}

				if(type=='caogao'){
					location.href = 'index.php?act=my';
				}else{					var zc_id=$("#zc_id").val();
					location.href = 'index.php?act=publish&op=step2&auction_id='+data.auction_id+'&auction_video_url='+auction_video_url+'&zc_id='+zc_id;
				}				
				return false;
			}
		});	
	});	
});
var video_url=$("#video_url").val();
if(video_url!=""){
	$("#xy_shipin").html("<video src='"+video_url+"' controls='controls' style='width:100%;'></video>");
}
</script>
</div>
</body>
</html>